﻿using System;
using fastCSharp;

namespace diantou.web.contest
{
    /// <summary>
    /// 问题运行效率排行榜
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class solutionRank : rank<solutionRank>
    {
        /// <summary>
        /// 问题运行效率排行榜缓存数据
        /// </summary>
        private struct cacheValue
        {
            /// <summary>
            /// 提交记录
            /// </summary>
            public diantou.dataAccess.contestJudge[] Judges;
            /// <summary>
            /// 总数量
            /// </summary>
            public int Count;
        }
        /// <summary>
        /// 问题运行效率排行榜客户端缓存
        /// </summary>
        private static readonly fastCSharp.sql.logCache<int, cacheValue>.array cache = new fastCSharp.sql.logCache<int, cacheValue>.array(diantou.dataAccess.tcpCall.contestJudge.onProblemSolutionLog, 4);
        /// <summary>
        /// 
        /// </summary>
        /// <param name="problemId"></param>
        /// <param name="language"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        private bool loadView(int problemId, diantou.dataModel.judgeState.languageType language, int page)
        {
            if (base.loadView(problemId))
            {
                fastCSharp.sql.logCache<int, cacheValue>.array.value cacheValue = language == dataModel.judgeState.languageType.All && page <= 1 ? cache.Get(problemId) : default(fastCSharp.sql.logCache<int, cacheValue>.array.value);
                if (cacheValue.Value.Judges == null)
                {
                    cacheValue.Value.Judges = diantou.dataAccess.tcpCall.contestJudge.getRank(problemId, language, 20, page, out cacheValue.Value.Count);
                    cache.Set(ref cacheValue);
                }
                pageInfo.Page = page;
                pageInfo.Set(20, cacheValue.Value.Count);
                load(cacheValue.Value.Judges);
                if (requestHeader.IsSearchEngine) pageInfo.Path = problem.Path.ContestAcceptedUser.ToPageString();
                return true;
            }
            return false;
        }
        /// <summary>
        /// 获取当前用户排行提交
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        protected override diantou.dataAccess.contestJudge getRank(out int index)
        {
            return diantou.dataAccess.tcpCall.contestJudge.getRank(currentUser.Id, query.problemId, query.language, out index);
        }

    }
}
